/* global Cesium viewer */
// 添加倾斜摄影
const addModel = function() {
	// var qxmoUrl = `http://172.25.110.41:8085/expo_3d/tileset.json`;
	var tilesetModel = new Cesium.Cesium3DTileset({
		// url: qxmoUrl,
	})
	// let that = this
	tilesetModel.readyPromise
		.then(function() {
			// let position = {"lon":110.18912,"lat":20.05923,"alt":176.796179655518,"heading":327.54937556911483,"pitch":-41.64145165873505,"roll":0}

			// that.IEflyTo(position)
			var params = {
				tx: 110.18912,
				ty: 20.05923,
				tz: 0, //修改高度
				rx: 0,
				ry: 0,
				rz: 0 //修改旋转
			}
			update3dtilesMaxtrix(tilesetModel)
			function update3dtilesMaxtrix() {
				//tileset
				//旋转
				var mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(params.rx))
				var my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(params.ry))
				var mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(params.rz))
				var rotationX = Cesium.Matrix4.fromRotationTranslation(mx)
				var rotationY = Cesium.Matrix4.fromRotationTranslation(my)
				var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz)
				//平移 修改经纬度
				var position = Cesium.Cartesian3.fromDegrees(params.tx, params.ty, params.tz)
				var m = Cesium.Transforms.eastNorthUpToFixedFrame(position)
				//旋转、平移矩阵相乘
				Cesium.Matrix4.multiply(m, rotationX, m)
				Cesium.Matrix4.multiply(m, rotationY, m)
				Cesium.Matrix4.multiply(m, rotationZ, m)
				//缩放 修改缩放比例
				var scale = Cesium.Matrix4.fromUniformScale(1)
				Cesium.Matrix4.multiply(m, scale, m)
				//赋值给tileset
				tilesetModel._root.transform = m
			}
			viewer.scene.primitives.add(tilesetModel)
			// viewer.zoomTo(tilesetModel);
		})
		.otherwise(function(error) {
			console.log(error)
		})
	// this.tileset = tilesetModel
}

export default addModel
